package com.aurora.CETManagementSystem.controller;

import com.aurora.CETManagementSystem.mapper.NewsMapper;
import com.aurora.CETManagementSystem.mapper.TestLogMapper;
import com.aurora.CETManagementSystem.mapper.UserInfoMapper;
import com.aurora.CETManagementSystem.pojo.Account;
import com.aurora.CETManagementSystem.pojo.News;
import com.aurora.CETManagementSystem.pojo.TestLog;
import com.aurora.CETManagementSystem.pojo.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 控制页面跳转Controller
 */
@Controller
public class RouterController {

    @Resource
    UserInfoMapper userInfoMapper;

    @Resource
    TestLogMapper testLogMapper;

    @Resource
    NewsMapper newsMapper;

    //登录页
    @RequestMapping({"/index","/"})
    public String index(){
        //获取当前的用户
        Subject subject = SecurityUtils.getSubject();

        //如果已经登陆过，直接跳转到DashBoard
        if(subject.isAuthenticated()){
            return "redirect:/toDashBoard";
        }

        return "index";
    }


    /**
     * 跳转到首页
     * @return
     */
    @RequestMapping("/toDashBoard")
    public String toDashBoard(Model model){


        List<Integer> cetSignNumbers = testLogMapper.selectCetSignNumbers();
        model.addAttribute("cetSignNumbers",cetSignNumbers);



        List<TestLog> recentTestLogs = testLogMapper.selectPage(new Page<TestLog>(1, 5), null).getRecords();

        model.addAttribute("recentTestLogs", recentTestLogs);

        return "student/dashboard";
    }


    /**
     * 跳转到考试资讯页面
     * @return
     */
    @RequestMapping("/toInformation")
    public String toInformation(Model model){
        List<News> news = newsMapper.selectList(null);
        model.addAttribute("news", news);
        return "student/information";
    }







}
